<?php
$this->Excel->openXls('files/templatePrm04kpi.xls');
$this->Excel->ajoutDonneeParColEtLigne(1,2,date('d/m/Y'));
$nbL=0;
$nbP=0;
$lg=6;
$col=2;
        $k=$kpiData['k'];
        $c=$kpiData['c'];
        $j=$kpiData['j'];
        $t=$kpiData['t'];
        $i=0;
        //debug($j);
?>
<h2><?php __('Number of Employees per Jobprofile PRM04_KPI')  ?></h2>
<table class="formstatus">
    <thead>
        <tr>
            <th><?php __('Job Profile') ?></th>
            <?php foreach($c as $key): ?>
                <th><?php __($key) ?></th>
                <?php $nbL++;  ?>
            <?php endforeach; ?>
        </tr>
    </thead>
    <tbody>
        <?php foreach($f as $fam):  $col=2;?> 
         <tr class="family"><td colspan="5" class="familyTd"><?php __($fam);  
         $this->Excel->ajoutDonneeParColEtLigne($col-1,$lg,$fam);
         $this->Excel->mergeAndStyleCells('B'.$lg.':X'.$lg);
         $lg++;
         ?></td></tr>
        <?php foreach($j as $jp): ?>
            <?php 
            $jps=$jp['Jobprofile'];
            if($i%2>0) $cls='impair'; else $cls='pair';
            if($i%2>0) $this->Excel->impCells('B'.$lg.':X'.$lg);
            ?>
       
            <?php if($jps['family']==$fam):  ?>
            <tr class="<?php echo $cls  ?>">
               <td><?php __($jps['title']) ?></td>
               <?php foreach ($k[$jps['title']] as $kpi): ?>
                    <td><?php __($kpi['prm04kpi']['Nb users']); 
                     $this->Excel->ajoutDonneeParColEtLigne($col,$lg,$kpi['prm04kpi']['Nb users']);
                    ?></td>
                    <?php $nbP++;$col++; ?>
               <?php endforeach; ?>
                    <?php if($nbL>$nbP){
                        while($nbL>$nbP){
                            echo '<td>0</td>';
                            $this->Excel->ajoutDonneeParColEtLigne($col,$lg,'0');
                            $nbP++;$col++;
                        }
                    }  ?>
            </tr>
            
            <?php $i++;$nbP=0; $lg++; ?>
            <?php endif; $col=2; ?>
            <?php endforeach;  ?>
        <?php endforeach; ?>
    </tbody>
</table>
<?php 

$this->Excel->saveAsXls('prm04kpi');
         $this->Excel->closeXls();
?>